package com.xhwl.centiotdata.converter.vehicle;


import cn.hutool.core.date.DateUtil;
import com.xhwl.centiotdata.pojo.dto.dahua.VehicleInOutRecordDaHuaDTO;
import com.xhwl.centiotdata.pojo.dto.fushi.VehicleInOutRecordFuShiDTO;
import com.xhwl.common.pojo.cent.vehicle.bo.config.VehicleIntegrationConfigBO;
import com.xhwl.common.pojo.cent.vehicle.bo.http.AccessRecordForInBO;
import com.xhwl.common.pojo.cent.vehicle.bo.http.AccessRecordForOutBO;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用于将第三方的出行记录实体类转换为中台熟知的实体类
 */
@Component
public class VehicleAccessRecordThirdConverter {

    /**
     * 转换大华icc进记录List
     */
    public List<AccessRecordForInBO> daHuaIcc2AccessRecordForInBOList(List<VehicleInOutRecordDaHuaDTO> vehicleInOutRecordDaHuaDTOList, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        return vehicleInOutRecordDaHuaDTOList.stream().map(s -> daHuaIcc2AccessRecordForInBO(s, vehicleIntegrationConfigBO)).collect(Collectors.toList());
    }


    /**
     * 大华icc进记录转换为AccessRecordForInBO
     */
    public AccessRecordForInBO daHuaIcc2AccessRecordForInBO(VehicleInOutRecordDaHuaDTO vehicleInOutRecordDaHuaDTO, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        AccessRecordForInBO accessRecordForInBO = new AccessRecordForInBO();
        if (vehicleInOutRecordDaHuaDTO != null) {
            accessRecordForInBO.setPlateNumber(vehicleInOutRecordDaHuaDTO.getCarNum());
            accessRecordForInBO.setCardType(daHuaIcc2CardType(vehicleInOutRecordDaHuaDTO.getOwnerType()));
            accessRecordForInBO.setEnterTime(vehicleInOutRecordDaHuaDTO.getEnterTimeStr());
            accessRecordForInBO.setEnterType(1);
            accessRecordForInBO.setEnterPictureUrl(vehicleIntegrationConfigBO.getVehicleParkingInfoBO().getHost() +
                    "/evo-apigw/" + vehicleInOutRecordDaHuaDTO.getRealCapturePicPathEnter());
            accessRecordForInBO.setEnterPassageName(vehicleInOutRecordDaHuaDTO.getEnterSluiceDevChnname());
            accessRecordForInBO.setRecordId(vehicleInOutRecordDaHuaDTO.getId());
        }
        accessRecordForInBO.setProjectId(vehicleIntegrationConfigBO.getVehicleSystemInfoBO().getProjectId());
        accessRecordForInBO.setParkId("");
        return accessRecordForInBO;
    }

    /**
     * 转换大华icc出记录List
     */
    public List<AccessRecordForOutBO> daHuaIcc2AccessRecordForOutBOList(List<VehicleInOutRecordDaHuaDTO> vehicleInOutRecordDaHuaDTOList, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        return vehicleInOutRecordDaHuaDTOList.stream().map(s -> daHuaIcc2AccessRecordForOutBO(s, vehicleIntegrationConfigBO)).collect(Collectors.toList());
    }

    /**
     * 大华icc出记录转换为AccessRecordForOutBO
     */
    public AccessRecordForOutBO daHuaIcc2AccessRecordForOutBO(VehicleInOutRecordDaHuaDTO vehicleInOutRecordDaHuaDTO, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        AccessRecordForOutBO accessRecordForOutBO = new AccessRecordForOutBO();
        if (vehicleInOutRecordDaHuaDTO != null) {
            accessRecordForOutBO.setPlateNumber(vehicleInOutRecordDaHuaDTO.getExitCarNum());
            accessRecordForOutBO.setCardType(daHuaIcc2CardType(vehicleInOutRecordDaHuaDTO.getOwnerType()));
            accessRecordForOutBO.setExitTime(vehicleInOutRecordDaHuaDTO.getExitTimeStr());
            accessRecordForOutBO.setExitType(1);
            accessRecordForOutBO.setExitPictureUrl(vehicleIntegrationConfigBO.getVehicleParkingInfoBO().getHost() +
                    "/evo-apigw/" + vehicleInOutRecordDaHuaDTO.getRealCapturePicPathExit());
            accessRecordForOutBO.setExitPassageName(vehicleInOutRecordDaHuaDTO.getExitSluiceDevChnname());
            accessRecordForOutBO.setRecordId(vehicleInOutRecordDaHuaDTO.getId());
        }
        accessRecordForOutBO.setProjectId(vehicleIntegrationConfigBO.getVehicleSystemInfoBO().getProjectId());
        accessRecordForOutBO.setParkId("");
        return accessRecordForOutBO;
    }

    private Integer daHuaIcc2CardType(String cardtype) {
        switch (cardtype) {
            case "0":
                return 3;
            case "1":
                return 2;
            case "2":
                return 1;
            case "3":
                return 0;
            default:
                return null;
        }
    }

    /**
     * 转换富士进记录List
     */
    public List<AccessRecordForInBO> fuShiList2AccessRecordForInBOList(List<VehicleInOutRecordFuShiDTO> vehicleInOutRecordFuShiDTOS, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        return vehicleInOutRecordFuShiDTOS.stream().map(s -> fuShiIcc2AccessRecordForInBO(s, vehicleIntegrationConfigBO)).collect(Collectors.toList());
    }


    /**
     * 富士进记录转换为AccessRecordForInBO
     */
    public AccessRecordForInBO fuShiIcc2AccessRecordForInBO(VehicleInOutRecordFuShiDTO vehicleInOutRecordFuShiDTO, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        AccessRecordForInBO accessRecordForInBO = new AccessRecordForInBO();
        if (vehicleInOutRecordFuShiDTO != null) {
            accessRecordForInBO.setPlateNumber(vehicleInOutRecordFuShiDTO.getTokenNo());
            accessRecordForInBO.setCardType(fuShi2CardType(vehicleInOutRecordFuShiDTO.getTcmId()));
            accessRecordForInBO.setEnterTime(DateUtil.parseDateTime(vehicleInOutRecordFuShiDTO.getInTime().replace("T", " ")));
            accessRecordForInBO.setEnterType(1);
            accessRecordForInBO.setEnterPictureUrl(vehicleInOutRecordFuShiDTO.getInPicture());
            accessRecordForInBO.setEnterPassageName(vehicleInOutRecordFuShiDTO.getInLaneName());
            accessRecordForInBO.setRecordId(vehicleInOutRecordFuShiDTO.getParkingId());
            accessRecordForInBO.setParkId(vehicleIntegrationConfigBO.getVehicleParkingInfoBO().getParkId());
        }
        accessRecordForInBO.setProjectId(vehicleIntegrationConfigBO.getVehicleSystemInfoBO().getProjectId());
        return accessRecordForInBO;
    }

    /**
     * 转换富士出记录List
     */
    public List<AccessRecordForOutBO> fuShiList2AccessRecordForOutBOList(List<VehicleInOutRecordFuShiDTO> vehicleInOutRecordFuShiDTOS, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        return vehicleInOutRecordFuShiDTOS.stream().map(s -> fuShi2AccessRecordForOutBO(s, vehicleIntegrationConfigBO)).collect(Collectors.toList());
    }

    /**
     * 富士出记录转换为AccessRecordForOutBO
     */
    public AccessRecordForOutBO fuShi2AccessRecordForOutBO(VehicleInOutRecordFuShiDTO vehicleInOutRecordFuShiDTO, VehicleIntegrationConfigBO vehicleIntegrationConfigBO) {
        AccessRecordForOutBO accessRecordForOutBO = new AccessRecordForOutBO();
        if (vehicleInOutRecordFuShiDTO != null) {
            accessRecordForOutBO.setPlateNumber(vehicleInOutRecordFuShiDTO.getTokenNo());
            accessRecordForOutBO.setCardType(fuShi2CardType(vehicleInOutRecordFuShiDTO.getTcmName()));
            accessRecordForOutBO.setExitTime(DateUtil.parseDateTime(vehicleInOutRecordFuShiDTO.getOutTime().replace("T", " ")));
            accessRecordForOutBO.setExitType(1);
            accessRecordForOutBO.setExitPictureUrl(vehicleInOutRecordFuShiDTO.getOutPicture());
            accessRecordForOutBO.setExitPassageName(vehicleInOutRecordFuShiDTO.getOutLaneName());
            accessRecordForOutBO.setRecordId(vehicleInOutRecordFuShiDTO.getParkingId());
            accessRecordForOutBO.setParkId(vehicleIntegrationConfigBO.getVehicleParkingInfoBO().getParkId());
        }
        accessRecordForOutBO.setProjectId(vehicleIntegrationConfigBO.getVehicleSystemInfoBO().getProjectId());
        return accessRecordForOutBO;
    }

    private Integer fuShi2CardType(String cardtype) {
        switch (cardtype) {
            case "月租卡A":
            case "月租卡B":
            case "月租卡C":
            case "月租卡D":
                return 1;
            case "自动临停车":
            case "临时卡":
                return 3;
            case "储值卡A":
            case "储值卡B":
            case "储值卡C":
            case "储值卡D":
                return 2;
            case "时租卡A":
            case "时租卡B":
            case "时租卡C":
            case "时租卡D":
                return 6;
            case "高级管理卡":
                return 17;
            case "管理卡":
                return 18;
            case "消费卡A":
            case "消费卡B":
            case "消费卡C":
            case "消费卡D":
            case "消费卡E":
            case "消费卡F":
            case "消费卡G":
            case "消费卡H":
            case "消费卡I":
            case "消费卡J":
            case "消费卡K":
                return 19;
            case "非法开闸":
                return 20;
            case "贵宾卡A":
            case "贵宾卡B":
                return 9;
            default:
                return null;
        }
    }
}
